package com.gaogzhen.datastructure;

import cn.hutool.crypto.digest.MD5;
import com.gaogzhen.datastructure.linear.linkedList.LinkList;
import com.gaogzhen.datastructure.queue.ArrayQueue;
import com.gaogzhen.datastructure.stack.ExpressionEval;
import com.gaogzhen.datastructure.tree.BinarySearchTree;
import com.gaogzhen.datastructure.tree.RBTree;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {
//        String s = "23 + 323 * ( 16 - 6 ) + 33 * 2.2";
//        System.out.println(ExpressionEval.replaceAllBlank(s));
//        System.out.println(ExpressionEval.convertMid2Suffix(s));
//        testReg();
//        HashMap
//        testRBTree();
//        List<String> collect = Stream.of("1,2aa,3b,4cc,a5".split(",")).collect(Collectors.toList());
//        System.out.println(collect);
//        double d = 5 /12;
//        BigDecimal bigDecimal = new BigDecimal(5 / 12);
//        System.out.println(d);
       testEncoder();
        // testShuffle();

    }

    public static void testShuffle() {
        List<Integer> list = new ArrayList<>();
        list.add(33);
        list.add(23);
        list.add(92);
        list.add(100);
        list.add(22);
        list.add(3);
        list.add(82);
        list.add(98);
        Collections.shuffle(list);
        System.out.println(list);
    }

    public static void testEncoder() {

            String s = "1234";
            // String m = MD5.create().digestHex(s);
            String m = s;
            BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            System.out.println(passwordEncoder.encode(m));

    }

    public static void testRBTree() {
        RBTree<Integer, String> rbTree = new RBTree<>();
        rbTree.add(1, "aaa");
        rbTree.add(23, "sdf");
        rbTree.add(63, "434");
        rbTree.add(634, "r4f");
        rbTree.add(223, "2342");
        rbTree.add(22, "fwff");
        System.out.println(rbTree);
        System.out.println(rbTree.size());
//        System.out.println(rbTree.findNode(1));
        rbTree.removeRBTreeNode(223);
        System.out.println(rbTree);
        System.out.println(rbTree.size());
    }

    public static void testReg() {
        String reg = "\\$\\{(\\w+)\\}";
        String str = "${name}-${age}-${sex}";
        Pattern compile = Pattern.compile(reg);
        Matcher matcher = compile.matcher(str);
        while (matcher.find()) {
            System.out.println(matcher.group(1));
        }
    }


    public static void testExpressEval() {
        String s = "23 + 323 * ( 16 - 6 ) + 33 * 2.2";
        double v = ExpressionEval.calSuffix(ExpressionEval.convertMid2Suffix(s));
        System.out.println(v);
    }
    public static void testArrayQueue() {
        ArrayQueue<Integer> a = new ArrayQueue<>(5);
        a.add(342);
        a.add(34);
        a.add(2525);
        a.add(11);
        a.add(8483);
        System.out.println(a.size());
        while (!a.isEmpty()) {
            System.out.println(a.pop());
        }
        System.out.println(a.pop());
    }


    public static void testHeap() {
        Heap<Integer>  b = new Heap<>(10);
        Integer[] a = {66, 88, 22, 33, 11, 5, 7, 8, 12};
        b.addAll(a);
        System.out.println("b:" + b);
        while (!b.isEmpty()) {
            System.out.println("pop:" + b.pop());
        }
    }
    public static void testBinarySearchTree() {
        BinarySearchTree<Integer> b = new BinarySearchTree<>();
        b.add(66);
        b.add(88);
        b.add(22);
        b.add(33);
        b.add(11);
        b.add(5);
        b.add(7);
        b.add(8);
        b.add(12);
        System.out.println(b);
        System.out.println(b.size());
        System.out.println(b.remove(8));
        System.out.println(b);
        System.out.println(b.getMax());
        System.out.println(b.getMin());
        System.out.println("level:" + b.level());
    }

    public static void testLinkList() {
//        SequenceList<Integer> list = new SequenceList<>(20);
        LinkList<Integer> list = new LinkList<>();
        list.add(5);
        list.add(15);
        list.add(25);
        list.add(35);
        new ArrayList<>().trimToSize();
        System.out.println(list);

        list.add(0, 0);
        System.out.println(list);
        System.out.println("==========");
//        for (Integer x: list) {
//            System.out.println(x);
//        }
//
//        Iterator<Integer> iterator = list.iterator();
//        while (iterator.hasNext()) {
//            Integer next = iterator.next();
//            if (next == 25) {
//                iterator.remove();
//            }
//        }
        System.out.println("==========");
        System.out.println(list);
        System.out.println("==========");
        System.out.println("get:" + list.get(0));
        System.out.println("index5:" + list.indexOf(5));
        System.out.println("size:" + list.size());
        System.out.println("remove:" + list.remove(0));
        System.out.println(list);
        Object o = 25;
        System.out.println("remove:" + list.remove(o));
        System.out.println("indexOf:" + list.indexOf(35));
        System.out.println(list);
        System.out.println(list.isEmpty());
        list.clear();
        System.out.println(list.isEmpty());
        System.out.println(list);
    }
}
